/* expect : 37 pts */
#include <bits/stdc++.h>
using namespace std;

inline long long read()
{
	long long res = 0;
	char c = getchar();
	while(c < '0' || c > '9') c = getchar();
	while('0' <= c && c <= '9')
		res = (res << 1) + (res << 3) + c - '0', c = getchar();
	return res;
}
inline void write(long long x)
{
	if(x == 0) {putchar('0'); return ;}
	else if(x / 10) write(x / 10);
	putchar('0' + x % 10);
}

int n;
namespace Subtask_2
{
	long long s[30010]; int sn;
	inline void modify(long long x)
	{
		if(sn == 0) s[++sn] = x;
		else
		{
			for(int i = 1; i <= sn; ++i)
			{
				if(s[i] == x)
				{
					for(int j = i; j < sn; ++j)
						s[j] = s[j + 1];
					--sn;
					return ;
				}
				if(s[i] > x)
				{
					for(int j = sn + 1; j > i; --j)
						s[j] = s[j - 1];
					s[i] = x; ++sn;
					return ;
				}
			}
			s[++sn] = x;
		}
	}
	inline long long work()
	{
//		cerr << sn << " : "; for(int i = 1; i <= sn; ++i) cerr << s[i] << " "; cerr << '\n';
		if(sn == 0) return 0;
		long long res = 0, pl = s[1], pr = s[sn];
		long long l = s[1], r = s[sn];
		for(int i = 2; i <= sn; ++i)
		{
			long long tl = pl + s[i], tr = pr + s[sn - i + 1];
			if(tl <= r) r = tr;
			else
			{
				res += r - l;
				l = tl, r = tr;
			}
			pl = tl, pr = tr;
		}
		res += r - l;
		return res;
	}
	inline void solve()
	{
		for(int i = 1; i <= n; ++i)
		{
			modify(read());
			write(work()); putchar('\n');
		}
	}
}

int main()
{
	freopen("kte.in", "r", stdin);
	freopen("kte.out", "w", stdout);
//	ios::sync_with_stdio(false);
//	cin.tie(0), cout.tie(0);
	n = read();
	Subtask_2::solve();
	return 0;
}
